23 #define foreach(x, v) for (typeof (v).begin() x=(v).begin(); x !=(v).end(); ++x)
24 #define For(i, a, b) for (int i=(a); i<(b); ++i)
25 #define D(x) cout << #x " is " << x << endl
27 const int MAXN
= 1000005;
31 void precomputePrefixFunction(char s
[], int n
) {
33 for (int i
= 1; i
< n
; ++i
) {
35 while (f
[i
] > -1 and s
[f
[i
]+1] != s
[i
]) {
38 if (s
[f
[i
]+1] == s
[i
]) {
47 // s = " abcabcabcabc";
48 // precomputePrefixFunction(s);
49 // for (int i = 1; i < s.length(); ++i) {
50 // printf("%d ", f[i]);
57 if (n
== 1 and s
[0] == '.') break;
63 precomputePrefixFunction(s
, n
);
65 //printf("s = %s\n", s); for (int i = 0; i < s; ++i) { printf("%d ", f[i]); } puts("");
69 while (j
- 1 >= 0 and f
[j
-1] + 1 == f
[j
] and f
[j
] > 0) j
--;
72 if (f
[j
] != 0) periodSize
= n
;
73 if ((n
% periodSize
) != 0) periodSize
= n
;
74 //printf("periodSize is %d\n", periodSize);
75 assert((n
% periodSize
) == 0);
76 printf("%d\n", n
/ periodSize
);